//! 流程响应数据解析模型
//!

use super::workflow::*;
use serde::{Deserialize, Serialize};
use serde_json::Value;

pub type ToDoListResponseList = Vec<ToDoListResponse>;

/// 代办流程的基础信息。
///
/// - createTime: String 创建时间
/// - creatorId: String 创建人id
/// - creatorName: String 创建人名称
/// - currentNodeId: String 当前节点id
/// - currentNodeName: String 当前节点名称
/// - lastOperateTime: String 最后操作时间
/// - lastOperatorId: String 最后操作人id
/// - lastOperatorName: String 最后操作人名称
/// - receiveTime: String 接收时间
/// - requestId: String 请求id
/// - requestLevel: String 紧急程度
/// - requestName: String 请求标题
/// - status: String 路径状态
/// - sysName: String 系统名称 开了统一待办才会显示，并且受后台统一待办设置显示全称，简称，或不显示名称
/// - workflowBaseInfo: Json 流程基本信息
///
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ToDoListResponse {
    pub create_time: String,
    pub creator_id: String,
    pub creator_name: String,
    pub current_node_id: String,
    pub current_node_name: String,
    pub last_operate_time: String,
    pub last_operator_id: String,
    pub last_operator_name: String,
    pub receive_time: String,
    pub request_id: String,
    pub request_level: String,
    pub request_name: String,
    pub status: String,
    pub sys_name: String,
    pub workflow_base_info: WorkflowBaseInfo,
}

/// 流程信息（对外）
///
/// 获取流程的详细信息。
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct RequestResponse {
    pub code: String,
    pub data: RequestResponseData,
    pub err_msg: ErrMsg,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct RequestResponseData {
    pub can_edit: bool,
    pub can_view: bool,
    pub create_time: String,
    pub creator_id: String,
    pub creator_name: String,
    pub current_node_id: String,
    pub current_node_name: String,
    pub forward_button_name: String,
    pub last_operate_time: String,
    pub last_operator_name: String,
    pub message_type: String,
    pub must_input_remark: bool,
    pub need_affirmance: bool,
    pub reject_button_name: String,
    pub remark: String,
    pub request_id: String,
    pub request_level: String,
    pub request_name: String,
    pub status: String,
    pub subback_button_name: String,
    pub submit_button_name: String,
    pub subnoback_button_name: String,
    pub workflow_base_info: WorkflowBaseInfo,
    pub workflow_detail_table_infos: Vec<WorkflowDetailTableInfo>,
    pub workflow_html_show: Vec<Value>,
    pub workflow_html_templete: Vec<Value>,
    pub workflow_main_table_info: WorkflowMainTableInfo,
    pub workflow_request_logs: Vec<WorkflowRequestLog>,
}

/// 流程意见
/// 
/// 解析流程意见。
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct RequestLog {
    pub code: String,
    pub data: Vec<RequestLogData>,
    pub err_msg: ErrMsg,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct RequestLogData {
    pub speechattachmentid: i64,
    pub signdocids: String,
    pub nodeattribute: String,
    pub speech_attachmente9: String,
    pub operator_dept: String,
    pub tmp_log_id: String,
    pub operatedate: String,
    pub destnodeid: String,
    pub received_persons: String,
    pub nodeid: String,
    pub operator: String,
    pub annexdocids: String,
    pub handwrittensignid: String,
    pub signworkflowids: String,
    pub agentorbyagentid: String,
    pub iframe_id: String,
    pub remark_html: String,
    pub id: String,
    pub is_mobile: String,
    pub received_personids: String,
    pub remark_location: String,
    pub operatetime: String,
    pub logid: String,
    pub operatortype: String,
    pub agenttype: String,
    pub nodename: String,
    pub isbranche: String,
    pub fulltextannotation: String,
    pub logtype: String,
}

#[cfg(test)]
mod tests {

    use super::*;
    use serde_json;

    const JSON_STR: &str = r###"[
        {
          "createTime": "2019-12-18 02:30:27",
          "creatorId": "21532",
          "creatorName": "gny-one",
          "currentNodeId": "371847",
          "currentNodeName": "3",
          "lastOperateTime": "2019-12-24 18:29:27",
          "lastOperatorId": "21533",
          "lastOperatorName": "gny-two",
          "receiveTime": "2019-12-24 18:29:27",
          "requestId": "12460885",
          "requestLevel": "1",
          "requestName": "wwp-签字意见-gny-one-2019-12-17",
          "status": "2 至 3",
          "sysName": "",
          "workflowBaseInfo": {
            "formId": "-7667",
            "workflowId": "346664",
            "workflowName": "wwp-签字意见",
            "workflowTypeId": "78641",
            "workflowTypeName": "wwp-test"
          }
        },
        {
          "createTime": "2019-11-27 18:49:13",
          "creatorId": "21532",
          "creatorName": "gny-one",
          "currentNodeId": "358338",
          "currentNodeName": "1",
          "lastOperateTime": "2019-11-27 18:49:12",
          "lastOperatorId": "21532",
          "lastOperatorName": "gny-one",
          "receiveTime": "2019-11-27 18:49:12",
          "requestId": "11710135",
          "requestLevel": "1",
          "requestName": "wwp-提交确认-gny-one-2019-11-27",
          "status": "",
          "sysName": "",
          "workflowBaseInfo": {
            "formId": "-7175",
            "workflowId": "332664",
            "workflowName": "wwp-提交确认",
            "workflowTypeId": "78641",
            "workflowTypeName": "wwp-test"
          }
        }
      ]"###;

    #[test]
    fn test1() {
        let v = serde_json::from_str::<ToDoListResponseList>(JSON_STR);
        println!("{:#?}", v);
        assert!(v.is_ok());
        assert_eq!(v.unwrap().len(), 2);
    }
}
